home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2004 March / PCWMAR04.iso / Software / Trial / TestTrack Pro 6 / ttprowininstall.exe / %LSMAINDIR% / LicenseServer Help / wwhelp / wwhimpl / common / scripts / popup.js < prev    next >
Encoding:
JavaScript  |  2003-12-12  |  12.6 KB  |  451 lines

  1. // Copyright (c) 2000-2001 Quadralay Corporation.  All rights reserved.
  2. //
  3.  
  4. function  WWHPopup_Object(ParamThisPopupRef,
  5.                           ParamWindowRef,
  6.                           ParamPopupTranslateFunc,
  7.                           ParamPopupFormatFunc,
  8.                           ParamDivID,
  9.                           ParamTextID,
  10.                           ParamTimeout,
  11.                           ParamOffsetX,
  12.                           ParamOffsetY,
  13.                           ParamWidth)
  14. {
  15.   this.mThisPopupRef = ParamThisPopupRef;
  16.   this.mWindowRef    = ParamWindowRef;
  17.   this.mDivID        = ParamDivID;
  18.   this.mTextID       = ParamTextID;
  19.   this.mTimeout      = (ParamTimeout > 0) ? ParamTimeout : 0;
  20.   this.mOffsetX      = ParamOffsetX;
  21.   this.mOffsetY      = ParamOffsetY;
  22.   this.mWidth        = ParamWidth;
  23.  
  24.  
  25.   // Updated when popup triggered
  26.   //
  27.   this.mbVisible     = false;
  28.   this.mPositionX    = 0;
  29.   this.mPositionY    = 0;
  30.   this.mText         = "";
  31.   this.mSetTimeoutID = null;
  32.  
  33.   this.fTranslate     = ParamPopupTranslateFunc;
  34.   this.fFormat        = ParamPopupFormatFunc;
  35.   this.fEventString   = WWHPopup_EventString;
  36.   this.fDivTagText    = WWHPopup_DivTagText;
  37.   this.fShow          = WWHPopup_Show;
  38.   this.fPositionPopup = WWHPopup_PositionPopup;
  39.   this.fPopup         = WWHPopup_Popup;
  40.   this.fHide          = WWHPopup_Hide;
  41. }
  42.  
  43. function  WWHPopup_EventString()
  44. {
  45.   var  EventString = "null";
  46.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  47.  
  48.  
  49.   // Set event string based on browser type
  50.   //
  51.   if ((Browser == 1) ||  // Shorthand for Netscape
  52.       (Browser == 2) ||  // Shorthand for IE
  53.       (Browser == 4))    // Shorthand for Netscape 6.0
  54.   {
  55.     EventString = "event";
  56.   }
  57.   else
  58.   {
  59.     EventString = "null";
  60.   }
  61.  
  62.   return EventString;
  63. }
  64.  
  65. function  WWHPopup_DivTagText()
  66. {
  67.   var  DivTagText = "";
  68.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  69.   var  VisibleAttribute = "visibility: hidden";
  70.  
  71.  
  72.   // Update VisibleAttribute based on browser
  73.   //
  74.   if ((Browser == 3) ||  // Shorthand for iCab
  75.       (Browser == 4))    // Shorthand for Netscape 6.0 (Mozilla)
  76.   {
  77.     VisibleAttribute = "display: none";
  78.   }
  79.  
  80.   // Open DIV tag
  81.   //
  82.   DivTagText += "<div id=\"" + this.mDivID + "\" style=\"position: absolute ; z-index: 1 ; " + VisibleAttribute + " ; top: 0px ; left: 0px\">\n";
  83.  
  84.   // Expand out popup in browsers that support innerHTML accessor
  85.   //
  86.   if ((Browser == 2) ||  // Shortcut for IE
  87.       (Browser == 3) ||  // Shortcut for iCab
  88.       (Browser == 4))    // Shortcut for Netscape 6 (Mozilla)
  89.   {
  90.     DivTagText += this.fFormat(this.mWidth, this.mTextID,
  91.                                "Popup");
  92.   }
  93.  
  94.   // Close out DIV tag
  95.   //
  96.   DivTagText += "</div>\n";
  97.  
  98.   return DivTagText;
  99. }
  100.  
  101. function  WWHPopup_Show(ParamText,
  102.                         ParamEvent)
  103. {
  104.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  105.   var  bStartTimer = false;
  106.   var  PopupDocument = eval(this.mWindowRef + ".document");
  107.   var  TranslatedText;
  108.  
  109.  
  110.   // Reset the timeout operation to display the popup
  111.   //
  112.   if (this.mSetTimeoutID != null)
  113.   {
  114.     clearTimeout(this.mSetTimeoutID);
  115.  
  116.     this.mSetTimeoutID = null;
  117.   }
  118.  
  119.   // Check to see if there is anything to display
  120.   //
  121.   if ((ParamText != null) &&
  122.       (ParamEvent != null))
  123.   {
  124.     if (Browser == 1)  // Shorthand for Netscape 4.x
  125.     {
  126.       this.mPositionX = ParamEvent.layerX;
  127.       this.mPositionY = ParamEvent.layerY;
  128.  
  129.       this.mText = ParamText;
  130.  
  131.       bStartTimer = true;
  132.     }
  133.     else if (Browser == 2)  // Shorthand for IE
  134.     {
  135.       this.mPositionX = PopupDocument.body.scrollLeft + ParamEvent.x;
  136.       this.mPositionY = PopupDocument.body.scrollTop  + ParamEvent.y;
  137.  
  138.       // Workaround for IE 4.0 on Windows
  139.       //
  140.       if (WWHFrame.WWHBrowserInfo.mbWindowsIE40)
  141.       {
  142.         this.mPositionX = ParamEvent.x;
  143.         this.mPositionY = ParamEvent.y;
  144.       }
  145.  
  146.       this.mText = ParamText;
  147.  
  148.       if (WWHFrame.WWHBrowserInfo.mPlatform == 2)  // Shorthand for Macintosh
  149.       {
  150.         // Setting the position here before it is displayed
  151.         // corrects a bug under IE 5 on the Macintosh
  152.         //
  153.         PopupDocument.all[this.mDivID].style.pixelLeft = 0;
  154.         PopupDocument.all[this.mDivID].style.pixelTop  = 0;
  155.         TranslatedText = this.fTranslate(this.mText);
  156.         PopupDocument.all[this.mTextID].innerHTML = TranslatedText;
  157.         this.fPositionPopup();
  158.       }
  159.  
  160.       bStartTimer = true;
  161.     }
  162.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  163.     {
  164.       this.mPositionX = ParamEvent.layerX;
  165.       this.mPositionY = ParamEvent.layerY;
  166.  
  167.       this.mText = ParamText;
  168.  
  169.       bStartTimer = true;
  170.     }
  171.  
  172.     if (bStartTimer == true)
  173.     {
  174.       this.mSetTimeoutID = setTimeout(this.mThisPopupRef + ".fPopup()", this.mTimeout);
  175.     }
  176.   }
  177. }
  178.  
  179. function  WWHPopup_PositionPopup()
  180. {
  181.   var  PopupWindow   = eval(this.mWindowRef);
  182.   var  PopupDocument = eval(this.mWindowRef + ".document");
  183.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  184.   var  NewPositionX;
  185.   var  NewPositionY;
  186.   var  VisibleOffsetX;
  187.   var  VisibleOffsetY;
  188.   var  PopupWidth;
  189.   var  PopupHeight;
  190.  
  191.  
  192.   // Calculate new position for popup
  193.   //
  194.   NewPositionX = this.mPositionX + this.mOffsetX;
  195.   NewPositionY = this.mPositionY + this.mOffsetY;
  196.  
  197.   if (Browser == 1)  // Shorthand for Netscape 4.x
  198.   {
  199.     // Attempt to determine DIV tag dimensions
  200.     //
  201.     PopupWidth = this.mWidth;
  202.     if (PopupDocument.layers[this.mDivID].clip.width > PopupWidth)
  203.     {
  204.       PopupWidth = PopupDocument.layers[this.mDivID].clip.width;
  205.     }
  206.     PopupHeight = 60;  // Guess a value
  207.     if (PopupDocument.layers[this.mDivID].clip.height > PopupHeight)
  208.     {
  209.       PopupHeight = PopupDocument.layers[this.mDivID].clip.height;
  210.     }
  211.  
  212.     // Calculate maximum values for X and Y such that the
  213.     // popup will remain visible
  214.     //
  215.     VisibleOffsetX = PopupWindow.innerWidth  - this.mOffsetX - PopupWidth;
  216.     if (VisibleOffsetX < 0)
  217.     {
  218.       VisibleOffsetX = 0;
  219.     }
  220.     VisibleOffsetY = PopupWindow.innerHeight - this.mOffsetY - PopupHeight;
  221.     if (VisibleOffsetY < 0)
  222.     {
  223.       VisibleOffsetY = 0;
  224.     }
  225.  
  226.     // Confirm popup will be visible and adjust if necessary
  227.     //
  228.     if (NewPositionX > (PopupWindow.pageXOffset + VisibleOffsetX))
  229.     {
  230.       NewPositionX = PopupWindow.pageXOffset + VisibleOffsetX;
  231.     }
  232.     if (NewPositionY > (PopupWindow.pageYOffset + VisibleOffsetY))
  233.     {
  234.       NewPositionY = PopupWindow.pageYOffset + VisibleOffsetY;
  235.     }
  236.  
  237.     // Set popup position
  238.     //
  239.     PopupDocument.layers[this.mDivID].left = NewPositionX;
  240.     PopupDocument.layers[this.mDivID].top  = NewPositionY;
  241.   }
  242.   else if (Browser == 2)  // Shorthand for IE
  243.   {
  244.     // Attempt to determine DIV tag dimensions
  245.     //
  246.     PopupWidth = this.mWidth;
  247.     if (PopupDocument.all[this.mDivID].offsetWidth > PopupWidth)
  248.     {
  249.       PopupWidth = PopupDocument.all[this.mDivID].offsetWidth;
  250.     }
  251.     PopupHeight = 60;  // Guess a value
  252.     if (PopupDocument.all[this.mDivID].offsetHeight > PopupHeight)
  253.     {
  254.       PopupHeight = PopupDocument.all[this.mDivID].offsetHeight;
  255.     }
  256.  
  257.     // Calculate maximum values for X and Y such that the
  258.     // popup will remain visible
  259.     //
  260.     VisibleOffsetX = PopupDocument.body.clientWidth  - this.mOffsetX - PopupWidth;
  261.     if (VisibleOffsetX < 0)
  262.     {
  263.       VisibleOffsetX = 0;
  264.     }
  265.     VisibleOffsetY = PopupDocument.body.clientHeight - this.mOffsetY - PopupHeight;
  266.     if (VisibleOffsetY < 0)
  267.     {
  268.       VisibleOffsetY = 0;
  269.     }
  270.  
  271.     // Confirm popup will be visible and adjust if necessary
  272.     //
  273.     if (NewPositionX > (PopupDocument.body.scrollLeft + VisibleOffsetX))
  274.     {
  275.       NewPositionX = PopupDocument.body.scrollLeft + VisibleOffsetX;
  276.     }
  277.     if (NewPositionY > (PopupDocument.body.scrollTop + VisibleOffsetY))
  278.     {
  279.       NewPositionY = PopupDocument.body.scrollTop + VisibleOffsetY;
  280.     }
  281.  
  282.     // Set popup position
  283.     //
  284.     PopupDocument.all[this.mDivID].style.pixelLeft = NewPositionX;
  285.     PopupDocument.all[this.mDivID].style.pixelTop  = NewPositionY;
  286.   }
  287.   else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  288.   {
  289.     // Attempt to determine DIV tag dimensions
  290.     //
  291.     PopupWidth = this.mWidth;
  292.     if (PopupDocument.getElementById(this.mDivID).offsetWidth > PopupWidth)
  293.     {
  294.       PopupWidth = PopupDocument.getElementById(this.mDivID).offsetWidth;
  295.     }
  296.     PopupHeight = 60;  // Guess a value
  297.     if (PopupDocument.getElementById(this.mDivID).offsetHeight > PopupHeight)
  298.     {
  299.       PopupHeight = PopupDocument.getElementById(this.mDivID).offsetHeight;
  300.     }
  301.  
  302.     // Calculate maximum values for X and Y such that the
  303.     // popup will remain visible
  304.     //
  305.     VisibleOffsetX = PopupWindow.innerWidth  - this.mOffsetX - PopupWidth;
  306.     if (VisibleOffsetX < 0)
  307.     {
  308.       VisibleOffsetX = 0;
  309.     }
  310.     VisibleOffsetY = PopupWindow.innerHeight - this.mOffsetY - PopupHeight;
  311.     if (VisibleOffsetY < 0)
  312.     {
  313.       VisibleOffsetY = 0;
  314.     }
  315.  
  316.     // Confirm popup will be visible and adjust if necessary
  317.     //
  318.     if (NewPositionX > (PopupWindow.scrollX + VisibleOffsetX))
  319.     {
  320.       NewPositionX = PopupWindow.scrollX + VisibleOffsetX;
  321.     }
  322.     if (NewPositionY > (PopupWindow.scrollY + VisibleOffsetY))
  323.     {
  324.       NewPositionY = PopupWindow.scrollY + VisibleOffsetY;
  325.     }
  326.  
  327.     // Set popup position
  328.     //
  329.     PopupDocument.getElementById(this.mDivID).style.left = NewPositionX + "px";
  330.     PopupDocument.getElementById(this.mDivID).style.top  = NewPositionY + "px";
  331.   }
  332. }
  333.  
  334. function  WWHPopup_Popup()
  335. {
  336.   var  PopupDocument = eval(this.mWindowRef + ".document");
  337.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  338.   var  FormattedText;
  339.   var  TranslatedText;
  340.  
  341.  
  342.   if (this.mSetTimeoutID != null)
  343.   {
  344.     if (Browser == 1)  // Shorthand for Netscape 4.x
  345.     {
  346.       // Format popup contents for browser
  347.       //
  348.       FormattedText = this.fFormat(this.mWidth, this.mTextID,
  349.                                    this.fTranslate(this.mText));
  350.  
  351.       // Set popup contents
  352.       //
  353.       PopupDocument.layers[this.mDivID].document.open();
  354.       PopupDocument.layers[this.mDivID].document.write(FormattedText);
  355.       PopupDocument.layers[this.mDivID].document.close();
  356.  
  357.       // Position the popup
  358.       //
  359.       this.fPositionPopup();
  360.  
  361.       // Show the popup
  362.       //
  363.       PopupDocument.layers[this.mDivID].visibility = "visible";
  364.       this.mbVisible = true;
  365.     }
  366.     else if (Browser == 2)  // Shorthand for IE
  367.     {
  368.       // Format popup contents for browser
  369.       // Set popup contents
  370.       //
  371.       TranslatedText = this.fTranslate(this.mText);
  372.       PopupDocument.all[this.mTextID].innerHTML = TranslatedText;
  373.  
  374.       // Position the popup
  375.       //
  376.       this.fPositionPopup();
  377.  
  378.       // Show the popup
  379.       //
  380.       PopupDocument.all[this.mDivID].style.visibility = "visible";
  381.       this.mbVisible = true;
  382.     }
  383.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  384.     {
  385.       // Format popup contents for browser
  386.       // Set popup contents
  387.       //
  388.       TranslatedText = this.fTranslate(this.mText);
  389.       PopupDocument.getElementById(this.mTextID).innerHTML = TranslatedText;
  390.  
  391.       // Initial popup positioning before object size can be determined
  392.       //
  393.       this.fPositionPopup();
  394.  
  395.       // Show the popup
  396.       //
  397.       PopupDocument.getElementById(this.mDivID).style.display = "block";
  398.       this.mbVisible = true;
  399.  
  400.       // Position the popup
  401.       // Offset calculations may be off so we might need to reposition the popup
  402.       //
  403.       this.fPositionPopup();
  404.     }
  405.   }
  406.  
  407.   // Clear the setTimeout ID tracking field
  408.   // to indicate that we're done.
  409.   //
  410.   this.mSetTimeoutID = null;
  411. }
  412.  
  413. function  WWHPopup_Hide()
  414. {
  415.   var  Browser = WWHFrame.WWHBrowserInfo.mBrowser;
  416.   var  PopupDocument;
  417.  
  418.  
  419.   // Cancel the setTimeout value that would have
  420.   // displayed the popup
  421.   //
  422.   if (this.mSetTimeoutID != null)
  423.   {
  424.     clearTimeout(this.mSetTimeoutID);
  425.  
  426.     this.mSetTimeoutID = null;
  427.   }
  428.  
  429.   // Shutdown the popup
  430.   //
  431.   if (this.mbVisible == true)
  432.   {
  433.     PopupDocument = eval(this.mWindowRef + ".document");
  434.  
  435.     if (Browser == 1)  // Shorthand for Netscape 4.x
  436.     {
  437.       PopupDocument.layers[this.mDivID].visibility = "hidden";
  438.     }
  439.     else if (Browser == 2)  // Shorthand for IE
  440.     {
  441.       PopupDocument.all[this.mDivID].style.visibility = "hidden";
  442.     }
  443.     else if (Browser == 4)  // Shorthand for Netscape 6.x (Mozilla)
  444.     {
  445.       PopupDocument.getElementById(this.mDivID).style.display = "none";
  446.     }
  447.   }
  448.  
  449.   this.mbVisible = false;
  450. }
  451.